<template>
	<view>
		<goods-list :goodsList="goods"></goods-list>
	</view>
</template>

<script>
	import goodsList from '../../components/goods-list/goods-list.vue'
	
	export default {
		data() {
			return {
				goods:[],
				pageindex:0,
			}
		},
		components: {
			goodsList
		},
		onLoad() {
			this.getGoods()
		},
		onReachBottom() {
			console.log("触底了")
			this.getGoods()
		},
		onPullDownRefresh() {
			console.log("slsx")
			this.pageindex=0
			this.goods=[]
			setTimeout(()=>{
				this.getGoods(()=>{
					uni.stopPullDownRefresh()
				})
			},1000)
		},
		methods: {
			async getGoods(callback){
				this.pageindex++
				const res = await this.$request({url:"/api/getgoods",data:{pageindex:this.pageindex}})
				const len=res.data.message.length
				if(len===0){
					uni.showToast({
						title: '没有更多了'
					});
					return
				}
				this.goods=[...this.goods,...res.data.message]
				callback&&callback()
			}
		}
	}
</script>

<style>

</style>
